package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.bean.SpreadMealDetail
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ServiceMealDetailsViewModel : BaseViewModel() {
    val getSpreadMealDetailData = StatefulMutableLiveData<SpreadMealDetail>()
    fun getSpreadMealDetail(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<SpreadMealDetail>("api/store_api/get_spread_meal_detail", *params,
                onStart = {
                    getSpreadMealDetailData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getSpreadMealDetailData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getSpreadMealDetailData.value = StateData.Success(it)
                })
        }
    }
}